

export class Content {
    /**
     * 
     * @param {*} THREE  主体
     * @param {*} scene 场景（用于添加物体）
     * @param {*} camera 相机（视角）
     * @param {*} cnotrols 轨道控制器（查看）
     * @param {*} renderer 渲染器（主体）
     * @param {*} textureLoader 纹理加载器
     */
    constructor(THREE, scene, camera, cnotrols, renderer,textureLoader) {
        this.THREE = THREE;
        this.scene = scene;
        this.camera = camera;
        this.cnotrols = cnotrols;
        this.renderer = renderer;
        this.textureLoader= textureLoader
        //
        this.cubeParentMaterial=null
        this.planMaterial=null
    }
    object () {
        //添加物体
        const cubeParentGBox = new this.THREE.BoxGeometry(2, 2, 2)
        this.cubeParentMaterial = new this.THREE.MeshBasicMaterial({ color: 0xffff00 })
        //线框模式
        this.cubeParentMaterial.wireframe = true
        //创建物体
        const cubeParent = new this.THREE.Mesh(cubeParentGBox, this.cubeParentMaterial)
        cubeParent.position.set(0, 0, -3)
        console.log(cubeParentGBox.attributes.position.count) //24个顶点（按三角形算，每个点会重复）
        //
        const cubeGBox = new this.THREE.BoxGeometry(1, 1, 1)
        const cubeMaterial = new this.THREE.MeshBasicMaterial({ color: 0x00ff00 })
        const cube = new this.THREE.Mesh(cubeGBox, cubeMaterial)
        cube.position.set(0, 0, 3)
        // cube.rotation.x = Math.PI / 4
        cube.rotation.set(Math.PI / 4, 0, 0, "XYZ")
        cubeParent.add(cube)
        this.scene.add(cubeParent)
        //----------------------------------------------------------------
        //创建几何
        const geometry = new this.THREE.BufferGeometry()
        //使用索引绘制(如果是定点绘制就会有重复定点，如立方体有24个点)
        //逆时间顺序（否则得反面才看得见）
        const vertices = new Float32Array([
            -2, -2, -1,
            2, -2, -1,
            2, 2, -1,
            -2, 2, -1
        ])
        geometry.setAttribute('position', new this.THREE.BufferAttribute(vertices, 3))
        //创建索引(以vertices的坐标执行顺序)
        const indices = new Uint16Array([0, 1, 2, 2, 3, 0])
        geometry.setIndex(new this.THREE.BufferAttribute(indices, 1))
        
        
        const planeMateroal = new this.THREE.MeshBasicMaterial({
            color: 0x00ff00,
            side: this.THREE.DoubleSide, // 双面可看
            wireframe: true,
            // map 线框不能用map
        })
        
        const plane = new this.THREE.Mesh(geometry, planeMateroal)
        console.log(planeMateroal)
        this.scene.add(plane)
    }
    texture(){
        //
        //加载纹理
        /**
         * (默认是从public里加载 ./texture/images/)
         * 如果要吃src 里面加载 责需要
         * let texture=this.textureLoader.load(require('./assets/....'))
         **/
        let texture=this.textureLoader.load('./texture/watercover/CityNewYork002_COL_VAR1_1K.png')
        let aoMap=this.textureLoader.load('./texture/watercover/CityNewYork002_AO_1K.jpg')
        let planGeometry=new this.THREE.PlaneGeometry(2,2)
        let planMaterial =new this.THREE.MeshBasicMaterial({
            color:0xffffff,
            side: this.THREE.DoubleSide,
            map:texture,
            transparent:true, //允许透明
            aoMap:aoMap, // (如强化图片细节阴影)
        })
        this.planMaterial=planMaterial

        let planeHead = new this.THREE.Mesh(planGeometry,planMaterial)
        planeHead.position.set(0, 0, 3)
        this.scene.add(planeHead)
    }
    element(){
        let data={
            cubeParentMaterial:this.cubeParentMaterial,
            planMaterial:this.planMaterial
        }
        return data
    }
}

